package club.beimeng.emailserver.controller;

import club.beimeng.emailserver.entity.BEmail;
import club.beimeng.emailserver.service.EmailService;
import club.beimeng.emailserver.utils.BMResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;



@Api(tags = "邮件服务端口测试")
@RestController // 如果是controller 返回json 类型的数据将会报错404
@CrossOrigin
@RequestMapping("email_server")
public class EmailController {

    @Autowired
    public EmailService emailService;

    private final static java.util.logging.Logger logger = java.util.logging.Logger.getLogger("SendEmail");

    @ApiOperation("由BEmail")
    @PostMapping("sendByBEmail")
    public BMResult sendByBEmail(@RequestBody BEmail bEmail){ // 通过自定义类BEmail 发送邮件

        boolean b = emailService.receiveTask(bEmail);

        return b?BMResult.ok():BMResult.error();
    }

    @ApiOperation("由text")
    @PostMapping("sendByText")
    public BMResult sendByText(String[] recipients, String title, String html){// 通过字符串来发送邮件

        boolean b = emailService.receiveTask(recipients, title, html);

        return b?BMResult.ok():BMResult.error();
    }


}
